const http = require('../../utils/http.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  formSubmit(e) {
    let params = e.detail.value;

    if (!params.username || !params.password){
      wx.showToast({
        title: '请输入账号名或密码',
        icon:'none',
        duration:800
      })
      return;
    }

    http.get("/api/consumer/login", params).then(res=> {
      if (res.code == 200) {
        wx.setStorageSync("merchantCode", res.result);
        wx.redirectTo({
          url: "/pages/index/index"
        })
      }else {
        wx.showToast({
          title: res.message,
          icon:'none',
          duration:800
        })
      }
    })
  }
})
